package com.df.common;

import java.util.concurrent.ConcurrentHashMap;

public class SessionManager {

    //角色管理器
    public ConcurrentHashMap<String, Player> sessionMap = new ConcurrentHashMap<String, Player>();

    public void init(){

    }

    public boolean exists(String playerId) {
        if(sessionMap.containsKey(playerId)) {
            return true;
        }
        return false;
    }

    public boolean addPlayer(Player player) {
        sessionMap.put(player.getName(), player);
        return true;
    }
    public boolean removePlayer(String playerId) {
        sessionMap.remove(playerId);
        return true;
    }
    public boolean removePlayer(Player player) {
        sessionMap.remove(player.getName());
        return true;
    }

    private SessionManager(){}

    private enum Singleton{
        SINGLETON;
        SessionManager instance = new SessionManager();
        public static SessionManager getInstance(){
            return SINGLETON.instance;
        }
    }

    public static SessionManager getInstance(){
        return Singleton.SINGLETON.instance;
    }
}
